#include <gflags/gflags.h>

#include "blog_server.h"
#include "brpc.h"




DEFINE_int32(start_port, 38082, "start port");
// mysql
DEFINE_string(mysql_user,"lyt", "链接数据库的用户");
DEFINE_string(mysql_passwd,"001216", "链接数据库的密码");
DEFINE_string(mysql_db,"OJ", "要连接的数据库名称");
DEFINE_string(mysql_host,"43.143.245.137", "链接数据库的IP地址");
DEFINE_int32(mysql_port,33306, "链接数据库的端口");
DEFINE_string(mysql_charset,"utf8", "链接数据库的字符集");
DEFINE_int32(mysql_conn_pool,5, "链接数据库的连接池大小");
// reids
DEFINE_string(redis_host,"localhost", "redis连接本地");
DEFINE_int32(redis_port, 6379,"数据库的启动端口");
DEFINE_int32(redis_db, 0, "本地数据库默认启动id=0");
DEFINE_bool(redis_keep_alive, true, "防止空闲连接被断开");

// kafka
DEFINE_string(broker_host, "localhost:9092", "Kafka的broker地址列表");
DEFINE_string(topic_name, "user-action", "topic名称");

//es 
DEFINE_string(elasticsearch_host, "localhost:9200", "es的host");

//brpc 
DEFINE_string(value,"127.0.0.1:38082","value of register file_storage to etcd");
//etcd
DEFINE_string(etcd_host, "127.0.0.1:2379", "etcd addr");

int main(){
    lyt::EtcdNamingService name_server;
    brpc::NamingServiceExtension()->RegisterOrDie("etcd", &name_server);

    lyt::BlogServer::ptr server =lyt::BlogServerBuild()
        .make_odb_client(FLAGS_mysql_user, FLAGS_mysql_passwd, FLAGS_mysql_db, FLAGS_mysql_host, FLAGS_mysql_port, FLAGS_mysql_charset, FLAGS_mysql_conn_pool)
        .make_redis_client(FLAGS_redis_host, FLAGS_redis_port, FLAGS_redis_db,FLAGS_redis_keep_alive)
        .make_kafka_producer(FLAGS_broker_host, FLAGS_topic_name)
        .make_elasticsearch_client({FLAGS_elasticsearch_host})
        .make_blog_service()
        .make_brpc_server(FLAGS_start_port)
        .make_register(FLAGS_etcd_host,FLAGS_value)
        .build();

    server->start();
    return 0;
}